package com.keyinong.parkin.uploadeimg.utils;

import java.util.ArrayList;

import com.example.parkin.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;

public class UpTicketImgAdapter extends BaseAdapter {
	ArrayList<String> list;
	Context context;

	public UpTicketImgAdapter(ArrayList<String> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View view, ViewGroup parent) {
		ViewHandle handle;
		if (view == null) {
			handle = new ViewHandle();
			view = LayoutInflater.from(context).inflate(
					R.layout.item_grid_upticketimg, null);
			handle.img_ticketImg=(ImageView) view.findViewById(R.id.img_ticketImg);
		    handle.cb_img=(CheckBox) view.findViewById(R.id.cb_img);
		    view.setTag(handle);
		}else{
			handle=(ViewHandle) view.getTag();
		}
		String s = list.get(position);
		 if (!s.equals("3")) {
			 handle.cb_img.setVisibility(View.VISIBLE);
			 handle.img_ticketImg.setImageBitmap(ImageTool.createImageThumbnail(s));
         } else {
        	 handle.cb_img.setVisibility(View.GONE);
             handle.img_ticketImg.setImageResource(R.drawable.img_addticket_img);
         }
		 handle.cb_img.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 list.remove(position);
//                 refreshAdapter();
                 notifyDataSetChanged();
             }
         });

		return view;
	}

	private class ViewHandle {
		ImageView img_ticketImg;
        CheckBox cb_img;

	}

}
